const mysql = require('mysql2/promise');

async function checkBlueClothes() {
  const connection = await mysql.createConnection({
    host: '127.0.0.1',
    user: 'root',
    password: '302108jw302',
    database: 'wardrobe_db'
  });

  console.log('🔍 检查用户衣柜中的蓝色衣服...\n');

  try {
    // 查询所有蓝色相关的衣服
    const [blueClothes] = await connection.query(`
      SELECT id, name, color, category_id
      FROM clothing
      WHERE user_id = 1 AND (
        color LIKE '%蓝%' OR
        color LIKE '%blue%' OR
        name LIKE '%蓝%'
      )
      ORDER BY category_id, name
    `);

    console.log(`📊 找到 ${blueClothes.length} 件蓝色相关的衣服:`);
    
    if (blueClothes.length > 0) {
      // 直接显示
      blueClothes.forEach(item => {
        console.log(`   - ${item.name} (${item.color}) [分类ID: ${item.category_id}, ID: ${item.id}]`);
      });
    } else {
      console.log('❌ 没有找到任何蓝色衣服！');
    }

    // 查询所有颜色统计
    console.log('\n🎨 所有颜色统计:');
    const [colorStats] = await connection.query(`
      SELECT color, COUNT(*) as count
      FROM clothing 
      WHERE user_id = 1 AND color IS NOT NULL AND color != ''
      GROUP BY color
      ORDER BY count DESC
    `);

    colorStats.forEach(stat => {
      console.log(`   ${stat.color}: ${stat.count} 件`);
    });

    // 查询分类统计 - 简化版本
    console.log('\n📊 分类统计:');
    const [categoryStats] = await connection.query(`
      SELECT category_id, COUNT(*) as count
      FROM clothing
      WHERE user_id = 1
      GROUP BY category_id
      ORDER BY count DESC
    `);

    console.log('分类ID统计:');
    categoryStats.forEach(stat => {
      console.log(`   分类${stat.category_id}: ${stat.count} 件`);
    });

  } catch (error) {
    console.error('❌ 检查失败:', error);
  } finally {
    await connection.end();
  }
}

checkBlueClothes();
